﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace proLearningEnglish
{
    public partial class frmSetup : Form
    {
        private DataManager objDataManager;
        public frmSetup()
        {
            objDataManager = new DataManager();
            objDataManager.loadData("word.rdf");
            
            InitializeComponent();
            loadTest();
        }

        void addNode(TreeNode node, Word objWord)
        {
            TreeNode nodeTmp = node.Nodes.Add(objWord.getID(), objWord.getLabel());
            nodeTmp.Tag = objWord;
            List<Word> lst = objDataManager.getIsAChildWordNodes(objWord);
            for (int i = 0; i < lst.Count; i++)
            {
                addNode(nodeTmp, (Word)lst[i]);
            }
        }
        void addNode(TreeNode node, WordSense objWordSense)
        {
            TreeNode nodeTmp = node.Nodes.Add(objWordSense.getID(), objWordSense.getLabel());
            nodeTmp.Tag = objWordSense;
            List<WordSense> lst = objDataManager.getIsAChildWordSenseNodes(objWordSense);
            MessageBox.Show(lst.Count.ToString());
            for (int i = 0; i < lst.Count; i++)
            {
                addNode(nodeTmp, (WordSense)lst[i]);
            }
        }

        private void itemWordManager_Click(object sender, EventArgs e)
        {
            tabWordManager.Select();
            treWordTree.Nodes.Clear();
            List<Word> relationlist = objDataManager.getIsARootWordNodes();
            TreeNode nodeRoot = treWordTree.Nodes.Add("English Vocabulary");
            for (int i = 0; i < relationlist.Count; i++)
            {
                addNode(nodeRoot, (Word)relationlist[i]);
                
            }
            
            nodeRoot.Expand();            
        }

        private void setIndexInRowHeader(DataGridView grid)
        {
            dataGridView.TopLeftHeaderCell.Value = "STT";
            foreach (DataGridViewRow r in grid.Rows)
            {
                r.HeaderCell.Value = (r.Index + 1).ToString();
            }
        }

        private void loadTest()
        {
        }

        private void itemTestManager_Click(object sender, EventArgs e)
        {
            int i = 1;
            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                if (row.IsNewRow) continue;
                row.HeaderCell.Value = "Row " + i.ToString();
                i++;
            }
        }

        private void treWordTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            SimpleWord sw = (SimpleWord)e.Node.Tag;
            txtWord.Text = sw.getLabel();
            txtSense.Text = sw.getSense().getLabel();
            labWordType.Text = sw.getSense().getTypeString();
        }

        private void itemWordSenseManager_Click(object sender, EventArgs e)
        {
            tabWordSenseManager.Select();
            treWordSense.Nodes.Clear();
            List<WordSense> relationlist = objDataManager.getIsARootWordSenseNodes();
            TreeNode nodeRoot = treWordSense.Nodes.Add("Nghĩa tiếng Việt");
            for (int i = 0; i < relationlist.Count; i++)
            {
                addNode(nodeRoot, (WordSense)relationlist[i]);
            }
            nodeRoot.Expand(); 
        }

    }
}
